<%@ page session="false" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://myfaces.apache.org/trinidad" prefix="tr"%>
<%@ taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh"%>

<h:panelGroup>
	<jsp:include page="/order_search_form.jsp"/>

	<tr:table id="orderListDataTable" horizontalGridVisible="true"
		verticalGridVisible="true"
		binding="#{orderController.orderListDataTable}"
		inlineStyle="margin:3px"
		rendered="#{not empty orderController.orderList}"
		width="100%" emptyText="Lista jest pusta" rowBandingInterval="1"
		value="#{orderController.orderList}" var="order" rows="50">

		<tr:column sortable="true" sortProperty="number">
			<f:facet name="header">
				<h:outputText value="Numer" />
			</f:facet>
			<tr:outputText value="#{order.number}"/>
		</tr:column>
		<tr:column sortable="true" sortProperty="additionalStatus">
			<f:facet name="header">
				<h:outputText value="Wpłata" />
			</f:facet>
			<h:outputText value="#{order.additionalStatusEnum}" />
		</tr:column>
		<tr:column sortable="true" sortProperty="productCode" width="25%">
			<f:facet name="header">
				<h:outputText value="Product" />
			</f:facet>
			<h:outputText value="#{order.productCode}" />
		</tr:column>
		<tr:column sortable="true" sortProperty="totalamount" align="right">
			<f:facet name="header">
				<h:outputText value="Kwota" />
			</f:facet>
			<h:outputText value="#{order.totalamountForList}">
				<f:convertNumber groupingUsed="false" maxFractionDigits="2"
					minFractionDigits="2" locale="pl" />
			</h:outputText>
		</tr:column>
		<tr:column sortable="true" sortProperty="registrationdate">
			<f:facet name="header">
				<h:outputText value="Data rejestracji" />
			</f:facet>
			<tr:outputText value="#{order.registrationdate}">
				<f:convertDateTime pattern="dd-MM-yyyy" locale="pl" />
			</tr:outputText>
		</tr:column>
		<tr:column sortable="true" sortProperty="dateOfReceipt">
			<f:facet name="header">
				<h:outputText value="Data odbioru" />
			</f:facet>
			<tr:outputText value="#{order.dateOfReceipt}">
				<f:convertDateTime pattern="dd-MM-yyyy" locale="pl" />
			</tr:outputText>
		</tr:column>
		<tr:column align="right" sortable="true" sortProperty="daysTo"
			inlineStyle="#{(order.status != 3 && order.status != 4)? order.colorDateOfReceipt : ''}">
			<f:facet name="header">
				<h:outputText value="Do końca" />
			</f:facet>
			<tr:outputText value="#{order.daysTo}" />
		</tr:column>
		<tr:column sortable="true" sortProperty="clientName">
			<f:facet name="header">
				<h:outputText value="Klient" />
			</f:facet>
			<h:outputText value="#{order.clientName}" />
		</tr:column>
		<tr:column sortable="true" sortProperty="approved">
			<f:facet name="header">
				<tr:outputText value="Zat." shortDesc="Zatwierdzone" />
			</f:facet>
			<tr:selectBooleanCheckbox readOnly="true" selected="#{order.approvedBoolean}" />
		</tr:column>
		<tr:column sortable="true" sortProperty="status">
			<f:facet name="header">
				<h:outputText value="Status" />
			</f:facet>
			<h:outputText value="#{order.statusEnum}" />
		</tr:column>
		<tr:column sortable="true" sortProperty="responsible.login" rendered="#{empty OrderSearchCondition.salesmanResponsible}">
			<f:facet name="header">
				<h:outputText value="Odpow."
					title="Osoba odpowiedzialna za to zamówienie" />
			</f:facet>
			<h:outputText value="#{order.responsible.login}" />
		</tr:column>
		<tr:column align="center">
			<f:facet name="header">
				<h:outputText value="Edytuj" />
			</f:facet>
			<tr:commandLink shortDesc="Edytuj"
				rendered="#{currentUserTO.currentSalesman.permissionMap.ORDER_EDIT}"
				action="#{orderController.editOrder}">
				<tr:image source="gfx/edit.png" />
			</tr:commandLink>
		</tr:column>
		<tr:column align="center">
			<f:facet name="header">
				<h:outputText value="Usuń" />
			</f:facet>
			<tr:commandLink shortDesc="Usuń"
				action="#{orderController.removeOrder}"
				rendered="#{currentUserTO.currentSalesman.permissionMap.ORDER_REMOVE}"
				onclick="return confirmMessageBox('Czy chcesz usunąć zamówienie o numerze #{order.number} ?');">
				<tr:image source="gfx/delete.png" />
			</tr:commandLink>
		</tr:column>
		<f:facet name="detailStamp">
			<tr:panelGroupLayout inlineStyle="background-color:orange">
        		<tr:outputFormatted value="#{order.lastComment.note}" shortDesc="Napisała: #{order.lastComment.salesmanID.login}">
        			<f:converter converterId="FormatedTextConverter" />
				</tr:outputFormatted>
        	</tr:panelGroupLayout>
      	</f:facet>
	</tr:table>
</h:panelGroup>